home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / ds5000.md / machMigrate.c < prev    next >
C/C++ Source or Header  |  1990-02-23  |  7KB  |  234 lines

  1. /* 
  2.  * machMigrate.c --
  3.  *
  4.  *         Machine dependent code to support process migration.  These routines
  5.  *         encapsulate and deencapsulate the machine-dependent state of a
  6.  *    process and set up the state of the process on its new machine.
  7.  *
  8.  *    Copyright (C) 1989 Digital Equipment Corporation.
  9.  *    Permission to use, copy, modify, and distribute this software and
  10.  *    its documentation for any purpose and without fee is hereby granted,
  11.  *    provided that the above copyright notice appears in all copies.  
  12.  *    Digital Equipment Corporation makes no representations about the
  13.  *    suitability of this software for any purpose.  It is provided "as is"
  14.  *    without express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/kernel/mach/ds3100.md/RCS/machMigrate.c,v 9.1 90/02/22 21:30:45 douglis Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21. #include "sprite.h"
  22. #include "machConst.h"
  23. #include "machInt.h"
  24. #include "mach.h"
  25. #include "machMon.h"
  26. #include "sched.h"
  27. #include "procMigrate.h"
  28.  
  29. /*
  30.  * The information that is transferred between two machines.
  31.  */
  32. typedef struct {
  33.     Mach_UserState userState;        /* the contiguous machine-dependent
  34.                      * user state. */
  35. } MigratedState;
  36.  
  37.  
  38. /*
  39.  * ----------------------------------------------------------------------------
  40.  *
  41.  * Mach_EncapState --
  42.  *
  43.  *    Copy the machine-dependent information for a process into
  44.  *    a buffer.  The buffer passed to the routine must contain space for
  45.  *    a MigratedState structure, the size of which is accessible via 
  46.  *    another procedure.  
  47.  *
  48.  * Results:
  49.  *      SUCCESS.
  50.  *    The buffer is filled with the user state and PC of the process.
  51.  *
  52.  * Side effects:
  53.  *    None.
  54.  *
  55.  * ----------------------------------------------------------------------------
  56.  */
  57. /* ARGSUSED */
  58. ReturnStatus
  59. Mach_EncapState(procPtr, hostID, infoPtr, buffer)
  60.     register Proc_ControlBlock     *procPtr;  /* The process being migrated */
  61.     int hostID;                   /* host to which it migrates */
  62.     Proc_EncapInfo *infoPtr;           /* area w/ information about
  63.                         * encapsulated state */
  64.     Address buffer;               /* Pointer to allocated buffer */
  65. {
  66.     Mach_State *machStatePtr = procPtr->machStatePtr;
  67.     MigratedState *migPtr = (MigratedState *) buffer;
  68.     
  69.     /*
  70.      * Make sure we have the current floating point state.
  71.      */
  72.     if (machFPCurStatePtr == machStatePtr) {
  73.     MachGetCurFPState(machStatePtr);
  74.     machFPCurStatePtr = (Mach_State *)NIL;
  75.     }
  76.  
  77.     bcopy((Address) &machStatePtr->userState, (Address) &migPtr->userState,
  78.         sizeof(Mach_UserState));
  79.     return(SUCCESS);
  80. }    
  81.     
  82.  
  83. /*
  84.  * ----------------------------------------------------------------------------
  85.  *
  86.  * Mach_DeencapState --
  87.  *
  88.  *    Copy the machine-dependent information for a process from
  89.  *    a buffer.  The buffer passed to the routine must contain
  90.  *    a MigratedState structure created by Mach_EncapState on the
  91.  *    machine starting a migration.  
  92.  *
  93.  * Results:
  94.  *    The user state and PC of the process are initialized from the
  95.  *    encapsulated information, and the other standard process
  96.  *    initialization operations are performed (by the general initialization
  97.  *    procedure).  The status from that procedure is returned.
  98.  *
  99.  * Side effects:
  100.  *    None.
  101.  *
  102.  * ----------------------------------------------------------------------------
  103.  */
  104. /* ARGSUSED */
  105. ReturnStatus
  106. Mach_DeencapState(procPtr, infoPtr, buffer)
  107.     register Proc_ControlBlock     *procPtr; /* The process being migrated */
  108.     Proc_EncapInfo *infoPtr;          /* information about the buffer */
  109.     Address buffer;              /* buffer containing data */
  110. {
  111.     MigratedState *migPtr = (MigratedState *) buffer;
  112.     ReturnStatus status;
  113.  
  114.     /*
  115.      * Get rid of the process's old machine-dependent state if it exists.
  116.      */
  117.     if (procPtr->machStatePtr != (Mach_State *) NIL) {
  118.     Mach_FreeState(procPtr);
  119.     }
  120.  
  121.     /*
  122.      * This procedure relies on the fact that Mach_SetupNewState
  123.      * only looks at the Mach_UserState part of the Mach_State structure
  124.      * it is given.  Therefore, we can coerce the pointer to a Mach_State
  125.      * pointer and give it to Mach_UserState to get registers & such.
  126.      */
  127.  
  128.     status = Mach_SetupNewState(procPtr, (Mach_State *) &migPtr->userState,
  129.                 Proc_ResumeMigProc,
  130.                 migPtr->userState.regState.pc,
  131.                 TRUE);
  132.     /*
  133.      * Mach_SetupNewState thinks that all new processes have a clean FPU
  134.      * slate.  Override the place where it overrides the status register.
  135.      * (This could be handled by another arg to Mach_SetupNewState to
  136.      * indicate that the process is migrated, or by a kludge to see if the
  137.      * PC is Proc_ResumeMigProc, but neither one seems satisfactory.
  138.      */
  139.     if (proc_MigDebugLevel > 2) {
  140.     printf("Mach_DeencapState: FPU status register was %x.\n",
  141.            migPtr->userState.regState.fpStatusReg);
  142.     }
  143.     
  144.     procPtr->machStatePtr->userState.regState.fpStatusReg =
  145.     migPtr->userState.regState.fpStatusReg;
  146.  
  147.     return(status);
  148. }    
  149.     
  150.  
  151.  
  152. /*
  153.  * ----------------------------------------------------------------------------
  154.  *
  155.  * Mach_GetEncapSize --
  156.  *
  157.  *    Return the size of the encapsulated machine-dependent data.
  158.  *
  159.  * Results:
  160.  *    SUCCESS is returned directly; the size of the encapsulated state
  161.  *    is returned in infoPtr->size.
  162.  *
  163.  * Side effects:
  164.  *    None.
  165.  *
  166.  * ----------------------------------------------------------------------------
  167.  *
  168.  */
  169.  
  170. /* ARGSUSED */
  171. ReturnStatus
  172. Mach_GetEncapSize(procPtr, hostID, infoPtr)
  173.     Proc_ControlBlock *procPtr;            /* process being migrated */
  174.     int hostID;                    /* host to which it migrates */
  175.     Proc_EncapInfo *infoPtr;            /* area w/ information about
  176.                          * encapsulated state */
  177. {
  178.     infoPtr->size = sizeof(MigratedState);
  179.     return(SUCCESS);
  180. }
  181.  
  182.  
  183. /*
  184.  * ----------------------------------------------------------------------------
  185.  *
  186.  * Mach_CanMigrate --
  187.  *
  188.  *    Indicate whether a process's trapstack is in a form suitable for
  189.  *    starting a migration.
  190.  *
  191.  * Results:
  192.  *    TRUE if we can migrate using this trapstack, FALSE otherwise.
  193.  *
  194.  * Side effects:
  195.  *    None.
  196.  *
  197.  * ----------------------------------------------------------------------------
  198.  */
  199. /*ARGSUSED*/
  200. Boolean
  201. Mach_CanMigrate(procPtr)
  202.     Proc_ControlBlock *procPtr;        /* pointer to process to check */
  203. {
  204.     return(TRUE);
  205. }    
  206.     
  207.  
  208.  
  209. /*
  210.  *----------------------------------------------------------------------
  211.  *
  212.  * Mach_GetLastSyscall --
  213.  *
  214.  *    Return the number of the last system call performed for the current
  215.  *    process.
  216.  *
  217.  * Results:
  218.  *    The system call number is returned.
  219.  *
  220.  * Side effects:
  221.  *    None.
  222.  *
  223.  *----------------------------------------------------------------------
  224.  */
  225.  
  226. int
  227. Mach_GetLastSyscall()
  228. {
  229.     Proc_ControlBlock *procPtr;        /* pointer to process to check */
  230.  
  231.     procPtr = Proc_GetCurrentProc();
  232.     return(procPtr->machStatePtr->userState.regState.regs[T0]);
  233. }
  234.